#include "enemyspark.h"

EnemySpark::EnemySpark(QGraphicsScene *m_scene)
{
    root = QFileInfo(__FILE__).absolutePath();

    for(int i=0;i<6;i++){
        pix.append(QPixmap(root+"/res/spark"+QString::number(i+1)+".png"));
    }
    state = 6;
    scene = m_scene;
    setVisible(false);
    scene->addItem(this);
    symbol = false;
}

QRectF EnemySpark::boundingRect() const
{
    return QRectF(-pix[0].width()*0.5,-pix[0].height()*0.5,pix[0].width(),pix[0].height()-16);
}

void EnemySpark::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    if(state<=5){
        painter->drawPixmap(pix[state].width()*0.5,pix[state].height()*0.5,pix[state]);
        state = state+1;
    }else{
        symbol = false;
        setVisible(false);
        setPos(QPointF(-300,-300));
    }
}



void EnemySpark::setPos(const QPointF &pos)
{
    QGraphicsItem::setPos(pos);
}

void EnemySpark::setVisible(bool visible)
{
    QGraphicsItem::setVisible(visible);
}

void EnemySpark::setRotation(float angle)
{
    QGraphicsItem::setRotation(angle);
}

bool EnemySpark::isVisible()
{
    return QGraphicsItem::isVisible();
}

void EnemySpark::CallSpark()
{
    state = 0;
    setVisible(true);

}
